import request from '@u/request'

// 3.1 基础指标
/**
 * @namespace
 * @typedef {Object} Response
 * @property {boolean} success
 * @property {string} message
 * @property {Object} data
 */

/**
 * @namespace
 * @typedef {Object} PageInfo
 * @property {number} pageIndex
 * @property {number} pageSize
 */

/**
 * 查询基础指标列表
 * @param {{
 * areaId: string, 体检城市id
 * year: number| string, 体检年份
 * status: string, 发布状态
 * indexName: string, 体系名称
 * } & PageInfo } params
 * @returns {Promise<Response>}
 */
export function queryBaseIndexList(params) {
  return request({
    url: '/index/base/query',
    method: 'GET',
    params,
  })
}

/**
 * 查询基础指标详情
 * @param {string} pkid
 * @returns {Promise<Response>}
 */
export function queryBaseIndexDetail(pkid) {
  return request({
    url: '/index/base/get?pkid=' + pkid,
    method: 'GET',
  })
}

/**
 * 基础指标删除
 * @param {string} pkid
 * @returns {Promise<Response>}
 */
export function deleteBaseIndex(pkid) {
  return request({
    url: '/index/base/delete?pkid=' + pkid,
    method: 'DELETE',
  })
}

/**
 * 新增或者更新基本指标
 * @param data
 * @returns {Promise<Response> | *}
 */
export function addOrUpdateBaseIndex(data) {
  return request({
    url: '/index/base/addOrUpdate',
    method: 'POST',
    data,
  })
}

/**
 * 特色指标查询基本指标下拉框
 * @returns {Promise<Response> | *}
 */
export function queryBaseIndexPull() {
  return request({
    url: '/index/base/query/pull',
    method: 'GET',
  })
}

/**
 * 发布基础指标
 * @param {string} pkid
 * @param {string} status
 * @returns {Promise<Response>}
 */
export function publishBaseIndex(pkid, status) {
  return request({
    url: '/index/base/publish?pkid=' + pkid + '&status=' + status,
    method: 'GET',
  })
}

/**
 * 查询基础指标目录
 * @returns {Promise<Response>}
 */

export function queryBaseIndexCatalog(pkid) {
  return request({
    url: '/index/system/query/base?baseId=' + pkid,
    method: 'GET',
  })
}

// 3.2 特色指标

/**
 * 查询特色指标列表
 * @param {{
 * areaId: string, 体检城市id
 * year: number| string, 体检年份
 * status: string, 发布状态
 * indexName: string, 体系名称
 * } & PageInfo } params
 * @returns {Promise<Response>}
 */
export function querySpecialIndexList(params) {
  return request({
    url: '/index/special/query',
    method: 'GET',
    params,
  })
}

/**
 * 查询特色指标详情
 * @param {string} pkid
 * @returns {Promise<Response>}
 */
export function querySpecialIndexDetail(pkid) {
  return request({
    url: '/index/special/get?pkid=' + pkid,
    method: 'GET',
  })
}

/**
 * 特色指标删除
 * @param {string} pkid
 * @returns {Promise<Response>}
 */
export function deleteSpecialIndex(pkid) {
  return request({
    url: '/index/special/delete?pkid=' + pkid,
    method: 'DELETE',
  })
}

export function publishSpecialIndex(pkid, status) {
  return request({
    url: '/index/special/publish?pkid=' + pkid + '&status=' + status,
    method: 'GET',
  })
}

/**
 * 新增或者更新特色指标
 * @param data
 * @returns {Promise<Response> | *}
 */
export function addOrUpdateSpecialIndex(data) {
  return request({
    url: '/index/special/addOrUpdate',
    method: 'POST',
    data,
  })
}

// 3.3指标管理删除

/**
 * 删除指标目录
 * @param pkid
 * @returns {Promise<Response> | *}
 */
export function deleteIndexCatalog(pkid) {
  return request({
    url: '/index/system/catalog/delete?pkid=' + pkid,
    method: 'DELETE',
  })
}

/**
 * 删除指标数据项
 * @param pkid
 * @returns {Promise<Response> | *}
 */
export function deleteIndexData(pkid) {
  return request({
    url: '/index/system/data/delete?pkid=' + pkid,
    method: 'DELETE',
  })
}

/**
 * 删除指标评价
 * @param pkid
 * @returns {Promise<Response> | *}
 */
export function deleteIndexEvaluate(pkid) {
  return request({
    url: '/index/system/evaluate/delete?pkid=' + pkid,
    method: 'DELETE',
  })
}

/**
 * 查询指标运算符
 * @returns {Promise<Response> | *}
 */
export function queryOperation() {
  return request({
    url: '/index/system/query/operation',
    method: 'GET',
  })
}

/**
 * 查询指标图标
 * @returns {Promise<Response> | *}
 */
export function queryIcon() {
  return request({
    url: '/index/system/query/icon',
    method: 'GET',
  })
}

/**
 * 查询体检任务
 * @param params
 * @returns {*}
 */
export function queryTask(params) {
  return request({
    url: '/index/task/query',
    method: 'GET',
    params,
  })
}

/**
 * 新增或更新体检任务
 * @param data
 * @returns {*}
 */
export function addTask(data) {
  return request({
    url: '/index/task/addOrUpdate',
    method: 'POST',
    data,
  })
}

/**
 * 发布任务
 * @param pkid
 * @returns {*}
 */
export function publishTask(pkid, status) {
  return request({
    url: '/index/task/publish',
    method: 'POST',
    data: {
      pkid,
      status,
    },
  })
}

/**
 * 删除体检任务
 * @param pkid
 * @returns {*}
 */
export function deleteTask(pkid) {
  return request({
    url: '/index/task/delete?pkid=' + pkid,
    method: 'DELETE',
  })
}

/**
 * 查询体检任务填报
 * @param params
 * @returns {*}
 */
export function queryTaskFill(params) {
  return request({
    url: '/index/task/fill/query',
    method: 'GET',
    params,
  })
}

/**
 * 增加任务审核流程
 * @param data
 * @returns {*}
 */
export function addTaskApply(data) {
  return request({
    url: '/index/task/apply/add',
    method: 'POST',
    data,
  })
}

/**
 * 查询任务审核流程
 * @param resourceId
 * @returns {*}
 */
export function queryTaskApply(resourceId) {
  return request({
    url: '/index/task/apply/query?resourceId=' + resourceId,
    method: 'GET',
  })
}

/**
 * 查询填报页面的结果
 * @returns {*}
 * @param taskId
 * @param regionId
 */
export function queryResult(taskId, regionId) {
  return request({
    url: '/index/result/query?taskId=' + taskId + '&regionId=' + regionId,
    method: 'GET',
  })
}

/**
 * 新增或更新结果
 * @param data
 * @returns {Promise<AxiosResponse<any>> | *}
 */
export function addOrUpdateResult(data) {
  return request({
    url: '/index/result/addOrUpdate',
    method: 'POST',
    data,
  })
}

export function queryTotal(taskId, regionId) {
  return request({
    url: '/index/result/query/total?taskId=' + taskId + '&regionId=' + regionId,
    method: 'GET',
  })
}

export function querySubmit(params) {
  return request({
    url: '/index/submit/query',
    method: 'GET',
    params,
  })
}

export function changeSubmitStatus(pkid, status) {
  return request({
    url: '/index/submit/changeStatus?pkid=' + pkid + '&status=' + status,
    method: 'POST',
  })
}

export function uploadSubmit(params) {
  return request({
    url: '/index/submit/upload',
    method: 'POST',
    params,
  })
}

export function deleteSubmit(pkid) {
  return request({
    url: '/index/submit/delete?pkid=' + pkid,
    method: 'DELETE',
  })
}

export function exportExcel(ids) {
  return request({
    url: '/index/result/exportExcel',
    responseType: 'blob',
    method: 'POST',
    data: ids,
  })
}

export function exportWrite(ids) {
  return request({
    url: '/index/result/exportWrite',
    responseType: 'blob',
    method: 'POST',
    data: ids,
  })
}
